package org.algorithm.YaYa.数组.三月.第三周;

/**
 * @date 2022/03/17 10:08 PM
 * @description: 周五作业
 *
 *
 * url: https://leetcode-cn.com/problems/container-with-most-water/
 */
public class 盛最多水的容器 {

    public static void main(String[] args) {
        int[] nums = {1,8,6,2,5,4,8,3,7};
        System.out.println(maxArea(nums));
    }

    
    public static int maxArea(int[] nums){

        int l = 0, r = nums.length - 1;
        int ans = 0;
        while (l < r) {
            int area = Math.min(nums[l], nums[r]) * (r - l);
            ans = Math.max(ans, area);
            if (nums[l] <= nums[r]) {
                ++l;
            }
            else {
                --r;
            }
        }
        return ans;

    }


}
